package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.Good;
import com.ssm.sfzy.mapper.GoodMapper;
import com.ssm.sfzy.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author song
 * @date 2024年04月01日 9:08
 * @version:1.0
 */
@Service
public class GoodServiceImpl implements GoodService {

    @Autowired
    private GoodMapper goodMapper;

    @Override
    public void add(Good entity) {
        goodMapper.insert(entity);
    }

    @Override
    public void edit(Good entity) {
        goodMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
        goodMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        goodMapper.deleteBatch(ids);
    }

    @Override
    public List<Good> find(Good entity) {
        return goodMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Good entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<Good> list = goodMapper.select(entity);
        PageInfo<Good> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public Good findById(Integer id) {
        return goodMapper.selectById(id);
    }
}
